package nc.bs.gsp.pub.record.purchase;

import java.util.ArrayList;

import nc.bs.trade.comsave.BillSave;
import nc.vo.gsp.pub.record.purchase.RecordPurchaseVO;
import nc.vo.pub.AggregatedValueObject;
import nc.vo.pub.BusinessException;
import nc.vo.pub.CircularlyAccessibleValueObject;

public class RecordPurchaseBillSave extends BillSave {

	@Override
	public ArrayList saveBill(AggregatedValueObject billVo)
			throws BusinessException {
		
		ArrayList retAry = new ArrayList();
		if (billVo == null || billVo.getChildrenVO() == null
				|| billVo.getChildrenVO().length == 0) {
			return retAry;
		}
		CircularlyAccessibleValueObject[] itemVOs = billVo.getChildrenVO();
		AggregatedValueObject[] billVOs = new AggregatedValueObject[itemVOs.length];
		for (int i = 0; i < itemVOs.length; i++) {
			billVOs[i] = new RecordPurchaseVO();
			billVOs[i].setParentVO(itemVOs[i]);
			billVOs[i].setChildrenVO(null);
		}
		billVOs = saveBillComVos(billVOs);
		retAry.add(billVOs[0].getParentVO().getPrimaryKey());
		retAry.add(billVOs[0]);
		return retAry;
	}
}
